package com.longma.server.util;

import cn.hutool.extra.mail.MailAccount;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author HAIBO
 * @date 2021-05-06 19:53
 * @description
 */
@Configuration
public class MyMailUtil {
    @Value("${mail-account.host}")
    private String host;
    @Value("${mail-account.port}")
    private int port;
    @Value("${mail-account.from}")
    private String from;
    @Value("${mail-account.user}")
    private String user;
    @Value("${mail-account.pass}")
    private String pass;
    @Value("${mail-account.ssl-enable}")
    private boolean sslEnable;

    public static String generateMailBody(String time, String yuncangName, String url) {
        StringBuilder mailHtml = new StringBuilder()
                .append("<table align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse;\" width=\"600\"> <tbody> <tr> <td align=\"center\" style=\"padding: 20px 0 20px 0;border: 0px;background-color: #fffbe8;\"><img src=\"http://www.wxlongmax.com/en/images/logo.png\" style=\"display: block;\"></td> </tr> <tr> <td style=\"padding: 10px 20px 10px 20px;background-color: #fffbe8;\"> <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse;\" width=\"100%\"> <tbody> <tr> <td style=\"text-indent:2em;padding: 4px 2px 4px 2px;\">您在 <span style=\"border-bottom: 1px dashed rgb(204, 204, 204); position: relative; color: rgb(247, 8, 8);\" >")
                .append(time)
                .append("</span> 接收到云能仓(<span style=\"border-bottom: 1px dashed rgb(204, 204, 204); position: relative;color: rgb(247, 8, 8)\">")
                .append(yuncangName)
                .append("</span>)的预警信息，请尽快处理，并点击下面的链接进行反馈： </td> </tr> <tr> <td style=\"text-indent:4em;padding: 14px 2px 14px 2px;\"><a href=\" ")
                .append(url)
                .append("\" rel=\"noopener\" target=\"_blank\">")
                .append(url)
                .append("</a></td> </tr> <tr> <td style=\"text-indent:2em;padding: 4px 2px 40px 2px;\"> (如果您无法点击此链接，请将它复制到浏览器地址栏后访问。该链接有效期为48小时，并且点击一次后失效。)</td> </tr> <td style=\"color: #1b4665;padding: 4px 2px 14px 2px;\">无锡隆玛科技有限公司｜智慧云能仓</td> </tbody> </table> </td> </tr> </tbody> </table>");
        return mailHtml.toString();
    }

    @Bean
    public MailAccount mailAccount(){
        return new MailAccount().setHost(host)
                                .setPort(port)
                                .setFrom(from)
                                .setUser(user)
                                .setPass(pass)
                                .setSslEnable(sslEnable);
    }

}
